package com.tx.admin.charartertag.controller;

import com.tx.admin.tagrelate.pojo.dto.TagRelateListDTO;
import com.tx.admin.tagrelate.pojo.vo.TagRelateVO;
import com.tx.admin.teacher.pojo.vo.TeacherStatisticsVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import com.tx.core.common.entity.ApiPageResult;
import com.tx.core.common.entity.ApiResult;
import com.tx.core.common.entity.PageResult;
import com.tx.core.common.entity.SelectIdsDTO;
import com.tx.admin.charartertag.service.ChararterTagService;
import com.tx.admin.charartertag.pojo.dto.ChararterTagCreateDTO;
import com.tx.admin.charartertag.pojo.dto.ChararterTagUpdateDTO;
import com.tx.admin.charartertag.pojo.dto.ChararterTagListDTO;
import com.tx.admin.charartertag.pojo.vo.ChararterTagVO;
import com.tx.core.common.entity.ImportExcelDTO;
import jakarta.servlet.http.HttpServletResponse;

import java.util.List;

/**
 * <p>
 * 人物标签表 Controller
 * </p>
 *
 * @author sz-admin
 * @since 2025-05-04
 */
@Tag(name =  "人物标签表")
@RestController
@RequestMapping("chararter-tag")
@RequiredArgsConstructor
public class ChararterTagController  {

    private final ChararterTagService chararterTagService;

    @Operation(summary = "新增")
    @SaCheckPermission(value = "chararter.tag.create")
    @PostMapping
    public ApiResult<Void> create(@RequestBody ChararterTagCreateDTO dto) {
        chararterTagService.create(dto);
        return ApiResult.success();
    }

    @Operation(summary = "修改")
    @SaCheckPermission(value = "chararter.tag.update")
    @PutMapping
    public ApiResult<Void> update(@RequestBody ChararterTagUpdateDTO dto) {
        chararterTagService.update(dto);
        return ApiResult.success();
    }

    @Operation(summary = "删除")
    @SaCheckPermission(value = "chararter.tag.remove")
    @DeleteMapping
    public ApiResult<Void> remove(@RequestBody SelectIdsDTO dto) {
        chararterTagService.remove(dto);
        return ApiResult.success();
    }

    @Operation(summary = "列表查询")
    @SaCheckPermission(value = "chararter.tag.query_table")
    @GetMapping
    public ApiResult<PageResult<ChararterTagVO>> list(ChararterTagListDTO dto) {
        return ApiPageResult.success(chararterTagService.page(dto));
    }

    @GetMapping("detailMode")
    public ApiResult detailTagList(TagRelateListDTO dto) {
        List<TagRelateVO> chararterTagVOS = chararterTagService.detailTagList(dto);
        return ApiPageResult.success(chararterTagVOS);
    }

    @PostMapping("batchSaveRelative")
    public ApiResult batchSaveRelative(@RequestBody List<TagRelateVO> dtos) {
         chararterTagService.batchSaveRelative(dtos);
        return ApiPageResult.success();
    }

    @Operation(summary = "详情")
    @SaCheckPermission(value = "chararter.tag.query_table")
    @GetMapping("/{id}")
    public ApiResult<ChararterTagVO> detail(@PathVariable Object id) {
        return ApiResult.success(chararterTagService.detail(id));
    }

    @Operation(summary = "导入")
    @Parameters({
      @Parameter(name = "file", description = "上传文件", schema = @Schema(type = "string", format = "binary"), required = true),
    })
    @SaCheckPermission(value = "chararter.tag.import")
    @PostMapping("/import")
    public void importExcel(@ModelAttribute ImportExcelDTO dto) {
        chararterTagService.importExcel(dto);
    }

    @Operation(summary = "导出")
    @SaCheckPermission(value = "chararter.tag.export")
    @PostMapping("/export")
    public void exportExcel(@RequestBody ChararterTagListDTO dto, HttpServletResponse response) {
        chararterTagService.exportExcel(dto, response);
    }

    @Operation(summary = "标签模糊搜索")
    @GetMapping("/remote/{keyword}")
    public ApiResult<List<ChararterTagVO.TagEnum>> remoteSearch(@PathVariable String keyword) {
        if ("null".equals(keyword)){
            keyword = "";
        }
        return ApiResult.success(chararterTagService.remoteSearch(keyword));
    }

}